// pages/customNameplate/customNameplate.js
const app = getApp();
let Api = require('../../api/api.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        src:"",
        name:'',
        customNameplateText_1:'',
        wpid:'',
        tipText: '',
        showToast: false,
        wcid:'',
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let self = this;
        console.log(options)
        self.setData({
            name: options.name,
            src: options.src,
            wpid: options.wpid,
            wcid: options.wcid,
        })
    },
    //添加铭牌
    addNameplate:function(){
        let self = this;
        if (self.data.customNameplateText_1 == ''){
            self.setData({
                tipText: '请输入自定义铭牌文字',
                showToast: true
            })
            setTimeout(function () {
                self.setData({
                    tipText: '',
                    showToast: false
                })
            }, 1000)
            return;
        }
        let pages = getCurrentPages();
        let prevPage = pages[pages.length - 2];  //上一个页面
        for (let i = 0; i < prevPage.data.orderList.length; i++){
            let up = "orderList[" + i + "].customNameplateText";
            if (prevPage.data.orderList[i].wpid == self.data.wpid){
                prevPage.setData({
                    [up]: self.data.customNameplateText_1,
                    customvalue: prevPage.data.customvalue + '∑' + self.data.wcid + '∑' + self.data.customNameplateText_1
                })
            }
        }
        wx.navigateBack({
            delta: 1
        })
    },
    //输入铭牌文字
    addText:function(e){
        let self = this;
        self.setData({
            customNameplateText_1:e.detail.value
        })
    }
})